import { makeAutoObservable } from 'mobx'
import { createContext, useContext } from 'react'

export interface UserInfoProps {
    NickName?: string
    GameId?: number
    Account?: string
    Gender?: number
    HeadImg?: string
    Mobile?: string
    Email?: string
    Status?: number
    HasVip?: false,
    VipEndTime?: string
    Password?: string
    Token?: string
    DynamicPwd?: string
    SignStatus?: boolean
}

class UserInfoStore {
    constructor() {
        makeAutoObservable(this)
        this.setUserInfo = this.setUserInfo.bind(this)
        this.clearUserInfo = this.clearUserInfo.bind(this)
    }
    
    userInfo: UserInfoProps | null = null
    
    setUserInfo(info: UserInfoProps) {
        this.userInfo = { ...this.userInfo, ...info }
    }
    
    clearUserInfo() {
        this.userInfo = null
    }
    
}

const userInfoContent = createContext(new UserInfoStore())

export const useUserInfoStore = () => useContext(userInfoContent)
